import logging

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
myLogger = logging.getLogger("DoYunSuan")


class DoYunSuan:
    """四则运算类"""

    NAME = "Jisuanqi"
    num = 100

    def jia(self, a, b):
        """加法运算"""
        try:
            myLogger.info(f"处理加法运算: {a} + {b}")
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a + b
                if isinstance(a, float) or isinstance(b, float):
                    c = round(c, 2)  # 四舍五入保留两位小数
                print(f"加法运算: {a} + {b} = {c}")
                return c
            else:
                error_msg = "您是非法输入！"
                myLogger.warning(f"非法输入: {a}({type(a)}), {b}({type(b)})")
                return error_msg
        except Exception as e:
            error_msg = f"加法运算异常: {e}"
            myLogger.error(error_msg)
            return error_msg

    def jian(self, a, b):
        """减法运算"""
        try:
            myLogger.info(f"处理减法运算: {a} - {b}")
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a - b
                if isinstance(a, float) or isinstance(b, float):
                    c = round(c, 2)
                print(f"减法运算: {a} - {b} = {c}")
                return c
            else:
                error_msg = "显示错误！"
                myLogger.warning(f"非法输入: {a}({type(a)}), {b}({type(b)})")
                return error_msg
        except Exception as e:
            error_msg = f"减法运算异常: {e}"
            myLogger.error(error_msg)
            return error_msg

    def cheng(self, a, b):
        """乘法运算"""
        try:
            myLogger.info(f"处理乘法运算: {a} × {b}")
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a * b
                if isinstance(a, float) or isinstance(b, float):
                    c = round(c, 2)
                print(f"乘法运算: {a} × {b} = {c}")
                return c
            else:
                error_msg = "显示错误信息！您是非法输入！"
                myLogger.warning(f"非法输入: {a}({type(a)}), {b}({type(b)})")
                return error_msg
        except Exception as e:
            error_msg = f"乘法运算异常: {e}"
            myLogger.error(error_msg)
            return error_msg

    def chu(self, a, b):
        """除法运算"""
        try:
            myLogger.info(f"处理除法运算: {a} ÷ {b}")
            if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):
                error_msg = "显示错误信息！您是非法输入！"
                myLogger.warning(f"显示错误信息！非法输入: {a}({type(a)}), {b}({type(b)})")
                return error_msg

            if b == 0:
                error_msg = "显示错误信息！：除数不能为0"
                myLogger.error(error_msg)
                return error_msg

            c = a / b
            if isinstance(a, float) or isinstance(b, float):
                c = round(c, 2)
            print(f"除法运算: {a} ÷ {b} = {c}")
            return c

        except Exception as e:
            error_msg = f"除法运算异常: {e}"
            myLogger.error(error_msg)
            return error_msg